package com.zb.zeus.common.redis.service.impl;


import com.zb.zeus.common.redis.service.IRoundExpireTime;

import cn.hutool.core.util.RandomUtil;

/**
 * 根据基准值随机
 *
 * @author liangfan
 * @date 2021/07/13 10:49
 **/

public class BasicValueRoundExpireTime implements IRoundExpireTime {

    private long basicValue = 0L;

    public BasicValueRoundExpireTime(long basicValue) {
        this.basicValue = basicValue;
    }


    @Override
    public long getExpireTimeByRound(long basicExpireTime) {
        if (basicExpireTime <= 0) {
            return basicExpireTime;
        }

        long max = (basicValue / 2);
        long min = max - basicExpireTime;
        long rand = RandomUtil.randomLong(min, max);
        return basicExpireTime + rand;

    }
}
